/*
 * @(#)MPQueryRunnerFactory.java
 * Date 2013-08-31
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.mpq.query.es;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import us.hornerscorners.lamppost.ihecommon.config.IHEConfig;

import us.hornerscorners.lamppost.ihecommon.service.ElasticSearchSource;

import us.hornerscorners.lamppost.mpq.constant.MPQueryName;

import us.hornerscorners.lamppost.registry.constant.IQueryName;

import us.hornerscorners.lamppost.registry.model.QueryRequest;

import us.hornerscorners.lamppost.registry.query.es.FindDocumentsRunner;
import us.hornerscorners.lamppost.registry.query.es.FindFoldersRunner;
import us.hornerscorners.lamppost.registry.query.es.IQueryRunner;
import us.hornerscorners.lamppost.registry.query.es.IQueryRunnerFactory;

import us.hornerscorners.lamppost.registry.transformer.model.CodedElementTransformer;
import us.hornerscorners.lamppost.registry.transformer.model.PatientIdentifierTransformer;

import static us.hornerscorners.lamppost.mpq.constant.MPQueryName
    .FindDocumentsForMultiplePatients;
import static us.hornerscorners.lamppost.mpq.constant.MPQueryName
    .FindFoldersForMultiplePatients;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-08-31
 * @author         Jim Horner
 */
@ApplicationScoped
public class MPQueryRunnerFactory implements IQueryRunnerFactory {

    /** Field description */
    @Inject
    private CodedElementTransformer codedElementTransformer;

    /** Field description */
    @Inject
    private IHEConfig config;

    /** Field description */
    @Inject
    private PatientIdentifierTransformer patientIdentifierTransformer;

    /** Field description */
    @Inject
    private ElasticSearchSource source;

    /**
     * Constructs ...
     *
     */
    public MPQueryRunnerFactory() {

        super();
    }

    /**
     * Method description
     *
     *
     *
     * @return
     */
    @Override
    public IQueryRunner createQueryRunner(IQueryName iQueryName) {

        IQueryRunner result = null;

        MPQueryName queryName = MPQueryName.toQueryName(iQueryName.getUUID());

        switch (queryName) {

            case FindDocumentsForMultiplePatients :
                result = new FindDocumentsRunner(this.config, this.source,
                                                 this.codedElementTransformer,
                                                 this.patientIdentifierTransformer);

                break;

            case FindFoldersForMultiplePatients :
                result = new FindFoldersRunner(this.config, this.source,
                                               this.codedElementTransformer,
                                               this.patientIdentifierTransformer);

                break;
        }

        return result;
    }

    /**
     * Method description
     *
     *
     * @param queryRequest
     *
     * @return
     */
    @Override
    public IQueryRunner createQueryRunner(QueryRequest queryRequest) {
        return createQueryRunner(queryRequest.getQueryName());
    }
}
